// import { useStore } from 'vuex';
//import {store} from '@/store'
import { computed } from 'vue'
import router from '@/router/index';
/**
 * 用户权限
 */
export function usePermission () {
  let userPermission = computed<any>(() => {
    //return store.state.permission.permission;
    let name = router.currentRoute.value.name
    if (name === 'CustomerEdit') {
      name = 'Customer'
    }
    const USER_INFO = JSON.parse(sessionStorage.getItem('USER_INFO') || '{}') as any
    const find = USER_INFO.appList.find(i => i.routeAddress === name)
    return find?.permissions
  })
  function hasPermissionAll(permission: string[]) {
    return permission.every((v: string) => {
      return userPermission.value?.some((val: string) => val === v);
    })
  }

  function hasPermission(permission: string[]) {
    return permission.some((v: string) => {
      if (userPermission.value) {
        return userPermission.value?.some((val: string) => val === v);
      } else {
        return false
      }
    })
  }
  return {
    hasPermission,
    hasPermissionAll
  }
}
